package com.yl.chainStore.entity.pay

import com.baomidou.mybatisplus.annotation.IdType
import com.baomidou.mybatisplus.annotation.TableField
import com.baomidou.mybatisplus.annotation.TableId
import com.baomidou.mybatisplus.annotation.TableName
import com.yl.chainStore.common.Constants
import com.yl.chainStore.common.enums.TypeEnum
import com.yl.common.annotation.NoArg
import java.math.BigDecimal
import java.math.RoundingMode
import java.util.*

/**
 * <p>
 *      公司收款记录  公司订单收款记录
 * </p>
 *
 * @author cxw
 * @since 2021-07-30
 */
@NoArg
@TableName("pay_company_collection_log")
data class PayCompanyCollectionLog(

	/**
	 * id
	 */
	@TableId(value = "id", type = IdType.AUTO)
	var id: Long = 0,

	/**
	 * 客户
	 */
	@TableField("customer_id")
	var customerId: Long? = null,

	/**
	 *
	 * type = COMPANY_COLLECTION_TYPE_ORDER   为 pay_order_customer_pay_log 的 id
	 */
	@TableField("associate_id")
	var associateId: Long? = null,

	/**
	 * 订单id
	 */
	@TableField("order_id")
	var orderId: Long? = null,

	/**
	 * 类型
	 */
	@TableField("type")
	var type: TypeEnum? = TypeEnum.COMPANY_COLLECTION_TYPE_ORDER,

	/**
	 * 需收款
	 */
	@TableField("need_payment")
	var needPayment: Long,

	/**
	 * 实际收款
	 */
	@TableField("actual_payment")
	var actualPayment: Long,

	/**
	 * 欠款
	 */
	@TableField("arrears")
	var arrears: Long,

	/**
	 * 处理人
	 */
	@TableField("deal_user_id")
	var dealUserId: Long,

	@TableField(exist = false)
	var dealUserName: String? = null,

	/**
	 * 部门
	 */
	@TableField("dept_id")
	var deptId: Long ?= null,

	@TableField(exist = false)
	var subCompanyName: String? = null,

	/**
	 * 公司
	 */
	@TableField("company_id")
	var companyId: Long,

	/**
	 * 备注
	 */
	@TableField("remark")
	var remark: String ?= null,

	/**
	 * 时间
	 */
	@TableField("pay_time")
	var payTime: Date = Date()

){
	/**
	 * 实际付款
	 */
	@TableField(exist = false)
	var actualPaymentShow: BigDecimal?= null
		get() {

			if(field == null){
				return BigDecimal(actualPayment.div(Constants.OtherConfig.MONEY_TO_DB_DOUBLE)).setScale(2, RoundingMode.HALF_UP)
			}
			return field
		}
		set(value) {
			if(value != null){
				actualPayment = (value.multiply(BigDecimal(Constants.OtherConfig.MONEY_TO_DB_DOUBLE))).toLong()
				field = value
			}
		}
}
